const isPromise = (obj) => {
    return obj && typeof obj.then === 'function';
};

const myPromiseAll = (arr) => {
    let result = [];
    let completedCount = 0;

    return new Promise((resolve, reject) => {
        const processResult = (index, data) => {
            result[index] = data;
            completedCount++;

            if (completedCount === arr.length) {
                resolve(result);
            }
        };

        for (let i = 0; i < arr.length; i++) {
            if (isPromise(arr[i])) {
                arr[i].then(
                    (data) => processResult(i, data),
                    reject
                );
            } else {
                processResult(i, arr[i]);
            }
        }
    });
};


let p1 = Promise.resolve(3);
let p2 = 1337;
let p3 = new Promise((resolve, reject) => {
    setTimeout(resolve, 1000, 'foo');
});
myPromiseAll([p1, p2, p3]).then(values => {
    console.log(values); // [3, 1337, "foo"] 
}); 